<template>
	<view class="about-me-wrap" :class="[theme]">
		<eui-nav-bar title="安装二维码" color="#000000" backgroundColor="#ffffff" rightIcon="" />
		<view class="content flex-row-center">
			<eui-base-card class="card-box">
				<view class="flex-column-center top">
					<image src="@/static/img/logo.png" mode="scaleToFill" class="logo"/>
					<view class="label">管e通v5安装</view>
					<view class="describe">扫一扫二维码，即可下载安装</view>
				</view>
				<view  class="img-box">
					<image src="@/static/img/Install_barcode.png" mode="scaleToFill"/>
				</view>
				<view class="flex-row-center row-box">
					<view class="button save-button" @click="handleSave">保存图片</view>
					<view class="split-line-column"></view>
					<view class="button share-button" @click="handleshare">分享图片</view>
				</view>
			</eui-base-card>
		</view>
	</view>
</template>

<script setup type="ts">
	import {storeToRefs} from 'pinia'
	import { onLoad } from '@dcloudio/uni-app';
	import { ref } from 'vue'
	import { useThemeStore } from '@/store/themeStore';
	const themeStore = useThemeStore(); // 主题
	const { theme } = storeToRefs(themeStore);

	// 保存图片到相册
	const handleSave = () => {
		console.log('点击了保存');
		const tempFilePath = '../../../static/img/Install_barcode.png';
		uni.getImageInfo({
			src: tempFilePath,
			success: function (res) {
				uni.saveImageToPhotosAlbum({
					filePath: res.path, 
					success() {
						uni.showToast({
							title: '图片保存成功',
							icon: 'success',
						});
					},
					fail(err) {
					console.error('保存失败', err);
						uni.showToast({
							title: '图片保存失败',
							icon: 'none',
						});
					}
				});
			},
			fail(err) {
				console.error('获取图片信息失败', err);
				uni.showToast({
					title: '图片不存在',
					icon: 'none',
				});
			}
		});
	}
	// const handleshare = () => {
	// 	const tempFilePath = '../../../static/img/Install_barcode.png';
	// 	// 在分享之前获取图片的绝对路径
	// 	uni.getImageInfo({
	// 		src: tempFilePath,
	// 		success: function (res) {
	// 			console.log(71, res);
	// 			// 调用 uni.share API 进行分享
	// 			uni.share({
	// 				provider: 'weixin',  // 指定分享平台为微信
	// 				type: 2,  // type 2 表示分享图片
	// 				imageUrl: res.path,  // 图片的绝对路径
	// 				scene: 'WXSceneSession',
	// 				success() {
	// 					uni.showToast({
	// 						title: '分享成功',
	// 						icon: 'success',
	// 					});
	// 				},
	// 				fail(err) {
	// 					console.log('分享失败', err);
	// 					uni.showToast({
	// 						title: '分享失败',
	// 						icon: 'none',
	// 					});
	// 				}
	// 			});
	// 		},
	// 		fail(err) {
	// 			console.error('获取图片信息失败', err);
	// 			uni.showToast({
	// 				title: '图片不存在',
	// 				icon: 'none',
	// 			});
	// 		}
	// 	});
	// };
	
	const handleshare = () => {
		plus.share.getServices(function(s) {
			//this.shares = s;
			console.log(JSON.stringify(s));
			if (s && s.length > 0) {
				for (var i = 0; i < s.length; i++) {
					if (s[i].id == 'weixin') {
						if (plus.os.name != "iOS") {
							plus.share.sendWithSystem({
								type: 'image',
								pictures: ['../../../static/img/Install_barcode.png'],
							}, function(e) {
								console.log('分享成功');
							}, function(e) {
								console.log('分享失败：' + JSON.stringify(e));
							});
						} else {
							plus.share.sendWithSystem({
								thumbs: ['../../../static/img/Install_barcode.png'],
								//pictures: ['../../img/BarcodeDownload.jpg'],
							}, function(e) {
								console.log('分享成功');
							}, function(e) {
								console.log('分享失败：' + JSON.stringify(e));
							});
						}

					}
				}
			}
		}, function(e) {
			alert("获取分享服务列表失败：" + e.message);
		});
	}
	onLoad((option) => {

	})
</script>

<style lang="scss" scoped>
.about-me-wrap {
	height: 100%;
	width: 100%;
	background-color: $enjoy-bg-color;
}
.content {
	padding: 10px;
	width: 100%;
	box-sizing: border-box;
}

.logo {
	margin: 30px 0 16px;
	width: 62px;
	height: 62px;
}
.label {
	margin-bottom: 8px;
	color: #000000;
	font-family: PingFangSC, PingFang SC;
	font-weight: 400;
	font-size: 18px;
}
.describe {
	font-family: PingFangSC, PingFang SC;
	font-weight: 400;
	font-size: 12px;
	color: #888888;
	line-height: 17px;
}
.img-box {
	width: 190px;
	height: 190px;
	margin: 40px auto 40px;
	image {
		width: 100%;
		height: 100%;
	}
}
.row-box {
	width: 190px;
	height: 37px;
	margin: 0 auto 50px;
	box-sizing: border-box;
}
.button {
	flex: 1;
	height: 37px;
	line-height: 37px;
	font-family: PingFangSC, PingFang SC;
	font-weight: 400;
	font-size: 24rpx;
	color: var(--theme-color);
}
.save-button {
	padding-right: 30px;
	text-align: right;
}
.share-button {
	padding-left: 30px;
}
.split-line-column {
	width: 1px;
	height: 16px;
	background: #CCCCCC;
}

</style>